package com.kun.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.entity.SysFileStorage;
import com.kun.mapper.FileStorageMapper;
import com.kun.service.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kun.li
 */
@Service
public class FileStorageServiceImpl extends ServiceImpl<FileStorageMapper, SysFileStorage> implements FileStorageService {

    @Autowired
    private FileStorageMapper fileStorageMapper;


    @Override
    public List<Tree<String>> getFileStorageTree() {
        List<SysFileStorage> fileStorages = fileStorageMapper.selectList(Wrappers.emptyWrapper());
        List<Tree<String>> treeList = TreeUtil.build(fileStorages, "-1", (fileStorage, treeNode) -> {
            treeNode.setId(fileStorage.getStorageId());
            treeNode.setParentId(fileStorage.getStorageParentId());
            treeNode.setName(fileStorage.getStorageName());
        });
        return treeList;
    }
}
